package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅书籍");
        System.out.println("请输入你要借阅的书籍");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();
        int i =0;
        for(i =0;i<bookList.getUsedSize();++i) {
            Book book = bookList.getPos(i);
            if(bookList.getPos(i).bookName.equals(name)) {
                System.out.println("查找图书成功~~~"+"~~~图书信息如下：");
                System.out.println(book);
                if(book.getBorrowed()==false){//true
                    System.out.println("该书籍没有借出，可以借出");
                    book.setBorrowed(true);
                    System.out.println("借出成功");
                }else {
                    System.out.println("该书籍已经借出~~~");
                }
                return;
            }
        }
        if(i==bookList.getUsedSize()){
            System.out.println("没有找到这本书");
        }
    }
}
